<?php
namespace system\core;

/**
 * Autoloader
 * 
 * This class autoloads class files.
 * 
 * @author Steffen Brem <steffenbrem@gmail.com>
 * @package System.core
 */
class Autoloader 
{    
    /**
     * Load a class
     *  
     * @access public
     * @param string $class
     * @param bool $throwException
     * @return bool
     */
    public static function loadClass( $class, $throwException = TRUE )
    {
        $path = str_replace('\\', '/', trim($class, '\\')) . '.php';
        
        if ( file_exists($path) )
        {
            require_once $path;
            
            if ( ! class_exists($class) )
            {
                throw new \Exception('The classname in the file "' . $path . '" is corrupt.');
            }
            
            return TRUE;
        }
        else if ( $throwException === TRUE )
        {
            throw new \Exception('The class "' . $class . '" could not be loaded, file does not exist.');
        }
        
        return FALSE;
    }
    
    /**
     * Checks if the class file exists
     * 
     * @param string $class
     * @return bool
     */
    public static function classFileExists( $class )
    {
        $path = str_replace('\\', '/', trim($class, '\\')) . '.php';
        
        return file_exists($path);
    }
}

/* End of file Autoloader.php */